package cn.chen.miaosha.redis;

/**
 * 简单实现KeyPrefix
 */
public abstract class BasePrefix implements KeyPrefix{

    /** 有效期 **/
    private int expireSeconds;

    private String prefix;

    public BasePrefix(int expireSeconds,String prefix){
        this.expireSeconds = expireSeconds;
        this.prefix = prefix;
    }

    public BasePrefix(String prefix){
        this(0,prefix); //0代表永不过期
    }

    //0代表永不过期
    @Override
    public int expireSeconds() {
        return expireSeconds;
    }

    @Override
    public String getPrefix() {
        String className = getClass().getSimpleName();
        return className + ":" +prefix;
    }
}
